package com.wyy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wyy.pojo.Users;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @program: gytcb
 * @author: 吴磊
 * @create: 2021-06-07 10:52
 */
@Repository
public interface UserMapper extends BaseMapper<Users> {
    /**
     * 更新用户信息
     *
     * @param users
     * @return
     */
    Integer updateUser(Users users);

    /**
     * 删除用户
     *
     * @param users
     * @return
     */
    Integer deleteUser(Users users);

    /**
     * 通过用户名和密码获取用户
     *
     * @param userNickname
     * @param userPassword
     * @return
     */
    @Select("select * from users where (user_email = #{userNickname} or user_nickname = #{userNickname}) and user_password = #{userPassword}")
    Users login(@Param("userNickname") String userNickname,
                @Param("userPassword") String userPassword);

    /**
     * 通过用户ID获取用户信息
     *
     * @param userId
     * @return
     */
    @Select("select * from users where user_id = #{userId}")
    Users getUserById(@Param("userId") String userId);


    /**
     * 获取此用户所有的文章ID
     *
     * @param userId
     * @return
     */
    @Select("select article_id from articles where user_id = #{userId}")
    List<String> getUserArticleIdByUserId(@Param("userId") String userId);
}
